package com.szl.group.controller.web;

import com.szl.group.common.anno.ResponseResult;
import com.szl.group.common.model.R;
import com.szl.group.component.FileUploader;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Description :
 * @Author : shenxl
 * @Date: 2020-11-13 11:18
 */
@Slf4j
@Api(tags = {"文件"})
@RestController
@ResponseResult
@RequestMapping("/file")
@RequiredArgsConstructor
public class FileUpload {


    private final FileUploader fileUploader;


    @ApiOperation("文件上传")
    @PostMapping(value = "/upload")
    public void upload(@RequestParam("file") MultipartFile file) {

        fileUploader.upload(file);
    }

    @ApiOperation("文件删除")
    @DeleteMapping(value = "/delete")
    public R delete(@RequestParam("objectName") String objectName) {

        fileUploader.delete(objectName);
        return R.success();
    }
}
